package com.example.grpc.provider.interceptor;

import io.grpc.Metadata;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author liyuncong
 * @version 1.0
 * @file LogGrpcInterceptor
 * @brief LogGrpcInterceptor
 * @details Grpc log 拦截器，打印请求参数
 * @date 2022-11-09
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2022-11-09                  liyuncong          Created
 */
public class LogGrpcInterceptor implements ServerInterceptor {

    private static final Logger logger = LoggerFactory.getLogger(LogGrpcInterceptor.class);

    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
        ServerCall<ReqT, RespT> serverCall,
        Metadata metadata,
        ServerCallHandler<ReqT, RespT> serverCallHandler
    ) {
        logger.info(serverCall.getMethodDescriptor().getFullMethodName());
        return serverCallHandler.startCall(serverCall, metadata);
    }
}
